// 表单验证功能
let formElement = document.querySelector("form");
//密码长度写在这里，方面以后修改
let password_length = 6;
formElement.onsubmit = function (event) {
    // 取得密码
    let pwd = formElement.elements['password'];
    if (pwd.value.trim().length < password_length) {
        pwd.focus();
        return false;
    }
    let hobbies = formElement.hobbies;
    let hobbies_box = formElement.querySelector("#hobbies_box");
    // console.log(hobbies_box);
    let count = 0;
    for (let i = 0; i < hobbies.length; i ++) {
        if (hobbies[i].checked) {
            count ++;
            console.log(count);
        }
    }
    if (count != 2) {
        // hobbies_box.focus();
        // hobbies_box.style = 'border:1px solid lightpink';
        for (let i = 0; i < hobbies.length; i ++) {
            if (hobbies[i].checked) {
                hobbies[i].checked = false;
            }else {
                hobbies[i].checked = true;
            }
        }
        return false;
    }
    count = 0;
    let degreeOfEducation = formElement.degreeOfEducation;
    for (let i = 0; i < degreeOfEducation.length; i ++) {
        if (degreeOfEducation[i].checked) {
            count ++;
        }
    }
    if (count == 0) {
        degreeOfEducation[0].checked = true;
        return false;
    }
}